<template>
	<om-addpage :menuName="menuName" :busCode="busCode" @formSubmit="formSubmit" :showHistoryBtn="false">
		<view v-show="false">
			<input v-model="formdata.id" name="id" />
		</view>
		<om-sub title="离职交接事项">
			<uni-list>
				<uni-list-item v-for="(item, index) in formdata.objStr" :key="index" :avatar="index + 1" @click="openSubData(index, item)">
					<view>{{ item.itemName }}</view>
				</uni-list-item>
			</uni-list>
		</om-sub>
		<om-sub title="考勤和薪资">
			<uni-list>
				<uni-list-item  :showArrow="false">
					<view class="tui-flex">
						<view class="tui-col-6"><om-label label="离职打卡时间" required></om-label></view>
						<view class="tui-center  tui-col-6">
							<picker mode="multiSelector" :value="attEndDate" @change="bindAttEndDateChange" :range="attEndDateArray">
								<view class="tui-right">{{formdata.attEndDate?formdata.attEndDate:"请选择"}}</view>
							</picker>
						</view>
					</view>
				</uni-list-item>
				<uni-list-item :showArrow="false">
					<view class="tui-flex">
						<view class="tui-col-6"><om-label label="有效出勤工时"></om-label></view>
						<view class="tui-left  tui-col-6">
							<input type="number" v-model="formdata.attHours" name="attHours"  placeholder="请输入"/>
						</view>
					</view>
				</uni-list-item>
				<uni-list-item :showArrow="false">
					<view class="tui-flex">
						<view class="tui-col-6"><om-label label="出勤天数"></om-label></view>
						<view class="tui-left  tui-col-6">
							<input type="number" v-model="formdata.attDays" name="attDays"  placeholder="请输入"/>
						</view>
					</view>
				</uni-list-item>
				<uni-list-item :showArrow="false">
					<view class="tui-flex">
						<view class="tui-col-6"><om-label label="薪资停发"></om-label></view>
						<view class="tui-left  tui-col-6">
							<picker @change="bindPayStopFlagChange" :range="payStopFlagArray" range-key="text" :value="payStopFlagNum">
								<view class="tui-right" style="text-align: right;">{{ payStopFlagArray[payStopFlagNum] ? payStopFlagArray[payStopFlagNum] : "请选择"}}</view>
							</picker>
						</view>
					</view>
				</uni-list-item>
				<uni-list-item  :showArrow="false">
					<view class="tui-flex padding-bottom">
						<view class="tui-col-12"><om-label label="备注"></om-label></view>
					</view>
					<view class="tui-col-12">
						<textarea :auto-height="true" class="om-textarea" v-model="formdata.attRemark" name="attRemark" placeholder="请输入..." />
					</view>
				</uni-list-item>
			</uni-list>
		</om-sub>
	</om-addpage>
</template>

<script>
	const form = require("../../../static/js/formValidation.js")
	import dateTimePicker from '@/static/js/dateTimePicker.js';
	import { ignoreHtml,getUrl } from '@/static/js/common.js';
export default {
	data() {
		return {
			formdata: {
				id:"",
				attEndDate:dateTimePicker.getNewDate(),
				attHours:'',
				attDays:'',
				payStopFlag: false,
				attRemark:'',
				objStr: []
			},
			attEndDateArray:[],
			attEndDate:[],
			menuName: '',
			busCode: '',
			checkedit: false,
			edit: false,
			payStopFlagNum: '',
			payStopFlagArray: ['√']
		};
	},
	methods: {
		bindPayStopFlagChange(e){
			this.payStopFlagNum = e.detail.value
			this.formdata.payStopFlagName = this.payStopFlagArray[this.payStopFlagNum]
			this.formdata.payStopFlag = this.formdata.payStopFlagName == '√' ? true : false;
		},
		openSubData(index,item){
			let _that = this;
			// uni.setStorage({
			// 	key: 'pages-form-hr-u-leaveapprove-leaveapprove-new-checkedit-work-config-data-handleInfo',
			// 	data: item
			// });
			// let param = {
			// 	configDataCacheKey: 'pages-form-hr-u-leaveapprove-leaveapprove-new-checkedit-work-config-data-handleInfo',
			// 	cachename: 'pages-form-hr-u-leaveapprove-leaveapprove-new-checkedit-work-handleInfo',
			// 	index: index,
			// 	checkedit: _that.checkedit,
			// 	edit: _that.edit
			// };
			// let url = getUrl('/pages/form/hr-u-tlApproval/data-info-handleInfo', param);
			// uni.navigateTo({
			// 	url: url
			// });
		},
		/**
		 * 大于结束时间时自动更新结束时间
		 */
		bindAttEndDateChange(e) {
			let _that = this;
			_that.formdata.attEndDate = dateTimePicker.formatterDate(_that.attEndDateArray, e.detail.value, 4);
			_that.attEndDate = e.detail.value
		},
		formSubmit: function(formdata) {
			let _that = this;
			// _that.om.formSave('tlApproval/updateData',_that.formdata, _that);
			//表单规则
			let rules = [{
				name: "attEndDate",
				rule: ["required"], 
				msg: ["请选择考勤截止时间"]
			}];
			if(!formdata || Object.keys(formdata).length==0){
				formdata = _that.formdata
			}
			if(!formdata.id ){
				_that.om.toast('没有找到对应表单标识');
				return;
			}
			let checkRes = form.validation(formdata, rules);
			if (!checkRes) {
				_that.om.formSave('tlApproval/updateData',formdata, _that);
			} else {
				_that.om.toast(checkRes);
			}
		}
	},
	onLoad: function(options) {
		let _that = this;
		_that.menuName = options.title || '离职审批';
		uni.setNavigationBarTitle({
			title: _that.menuName
		});
		if(options.code){
			_that.busCode = options.code
		}else{
			_that.om.toast("没有表单编码")
		}
		if(options.fileId){
			_that.formdata.id = options.fileId
		}else{
			_that.om.toast("没有表单ID")
		}
		if(options.checkedit){
			_that.checkedit = options.checkedit
		}
		if(options.edit){
			_that.edit = options.edit
		}
		
		if(_that.formdata.id){
			//加载表单信息
			_that.om.request('tlApproval/getInfo',{
				id:_that.formdata.id
			},'post').then(res => {
				if(res.succeed){
					_that.formdata = res.value.tlApproval
					_that.formdata.objStr = res.value.tlApproval_handles 
					// _that.formdata = res.value.tlApproval
					// let obj;
					// if(res.value.tlApproval.attEndDate){
					// 	obj = dateTimePicker.dateTimePicker(dateTimePicker.getNewYear()-1,dateTimePicker.getNewYear()+1,res.value.tlApproval.attEndDate);
					// }else{
					// 	obj = dateTimePicker.dateTimePicker(dateTimePicker.getNewYear()-1,dateTimePicker.getNewYear()+1)
					// }
					// obj.dateTime.pop();
					// obj.dateTimeArray.pop();
					// _that.attEndDateArray = obj.dateTimeArray;
					// _that.formdata.attEndDate = dateTimePicker.formatterDate(obj.dateTimeArray, obj.dateTime, 4);
					// _that.attEndDate = obj.dateTime
				}
			})
		}else{
			// let obj = dateTimePicker.dateTimePicker(dateTimePicker.getNewYear()-1,dateTimePicker.getNewYear()+1);
			// obj.dateTime.pop();
			// obj.dateTimeArray.pop();
			// _that.attEndDateArray = obj.dateTimeArray;
			// _that.formdata.attEndDate = dateTimePicker.formatterDate(obj.dateTimeArray, obj.dateTime, 4);
			// _that.attEndDate = obj.dateTime
		}
	},
	onShow() {
		// let _that = this
		// for (var fieldId in _that.subEditorObj) {
		// 	let editor = _that.subEditorObj[fieldId];
		// 	uni.getStorage({
		// 		key: getWorkCacheKey(fieldId),
		// 		success: function(res) {
		// 			editor.workList = res.data;
		// 			uni.removeStorage({
		// 				key: getWorkCacheKey(fieldId)
		// 			});
		// 		}
		// 	});
		// }
	}
};
</script>

<style></style>
